//
//  STTools_BaseViewController.m
//  blanket
//
//  Created by coder on 2017/12/4.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "STTools_BaseViewController.h"

@interface STTools_BaseViewController ()

@end

@implementation STTools_BaseViewController
+ (void)load{
    //导航栏分割线
    UIImage * image = [UIImage stoneobs_fun_st_imageWithColor:[UIColor clearColor]
                                            size:CGSizeMake(STONEOBS_UI_UISCREEN_WIDTH, 1)];
    [[UINavigationBar appearance] setShadowImage:image];
    
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}
- (STTools_BaseNavagationView *)cus_navgationBar{
    if (!_cus_navgationBar) {
        __weak typeof(self) weakSelf =  self;
        STTools_BaseNavagationView * cus_navgationBar =  [STTools_BaseNavagationView defultNavgaitionView];
        [cus_navgationBar.rightButton stoneobs_fun_touch_handle:^(UIButton *sender) {
            [weakSelf stoneobs_fun_st_rightBarAction:nil];
        }];
        _cus_navgationBar = cus_navgationBar;
        [self.view addSubview:cus_navgationBar];
        self.navigationController.navigationBar.hidden = YES;
    }
    return _cus_navgationBar;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.blackColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
    self.navigationController.navigationBar.barTintColor =  UIColor.whiteColor;
    
    self.navigationController.navigationBar.translucent = NO;
    //关闭透明 带来的view 坐标下移
    self.extendedLayoutIncludesOpaqueBars = YES;
    
    self.rt_disableInteractivePop = NO;
//    self.view.backgroundColor = UIColor.whiteColor;
    if (self.rt_navigationController.childViewControllers.count>1) {
        [self stoneobs_fun_st_setLeftItemWithImage:[UIImage imageNamed:@"icon_nav_back"]];
    }
    
    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    
    // Do any additional setup after loading the view.
}
- (void)setBackRowType:(NSInteger)type{
    
    if (type) {
        if (self.rt_navigationController.childViewControllers.count>1) {
            [self stoneobs_fun_st_setLeftItemWithImage:[UIImage imageNamed:@"happy_game_wh_icon_nav_back"]];
        }
        
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.blackColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
    }else{
        if (self.rt_navigationController.childViewControllers.count>1) {
            [self stoneobs_fun_st_setLeftItemWithImage:[UIImage imageNamed:@"happy_game_wh_icon_nav_back"]];
        }
        
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
    }
    
    
    
}
- (void)stoneobs_fun_st_leftBarAction:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated{
    vc.hidesBottomBarWhenPushed = YES;
    if (self.navigationController) {
        [self.navigationController pushViewController:vc animated:animated];
    }else{
        [TMUtils.stoneobs_fun_get_currentTopController pushViewController:vc animated:animated];
    }
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.view bringSubviewToFront:_cus_navgationBar];
    self.didLoad = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];

}

@end


@implementation UIViewController (STTools_BaseViewController)
- (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated{
    vc.hidesBottomBarWhenPushed = YES;
    if (self.navigationController) {
        [self.navigationController pushViewController:vc animated:animated];
    }else{
        [TMUtils.stoneobs_fun_get_currentTopController pushViewController:vc animated:animated];
    }
    
}
@end

